package com.swt.controller.S_controller;

import com.alibaba.fastjson.JSON;
import com.swt.domain.Image;
import com.swt.domain.User;
import com.swt.service.S_service.GetUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
public class GetUserController {
    @Resource
    private GetUserService getUserService;

    /*获取session的user对象*/
    @RequestMapping("/S_getUser")
    @ResponseBody
    public String getUser(HttpServletRequest request,HttpServletResponse response){
        User user = (User)request.getSession().getAttribute("USER_SESSION_KEY");
        User user1=getUserService.getUserById(user.getUserId());
        String user2=JSON.toJSONString(user1);
        return user2;
    }


    /**
     * 获取轮播图
     * */
    @RequestMapping("/S_getImage")
    @ResponseBody
    public String getImage(){
        List<Image>list=getUserService.getImage();
        return JSON.toJSONString(list);
    }

}
